package com.rose.redis._distributed_lock.impl;

import com.rose.redis._distributed_lock.LockConstant;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author: zhu.chen
 * @date: 2020/12/31
 * @version: v1.0.0
 */
//@Component
public class LockFactory extends LockConstant implements ApplicationContextAware {

    private static RedissonClient redissonClient;

    /**
     * 可重入锁
     *
     * @return
     */
    public static RLock getReentrantLock() {
        return redissonClient.getLock(LOCK_RESOURCE_NAME);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        LockFactory.redissonClient = applicationContext.getBean(RedissonClient.class);
    }

}
